package com.xhwl.logistics.converter.mapstruct;

import com.xhwl.logistics.bo.VehiclePassageBO;
import com.xhwl.logistics.bo.VehiclePassageSecondBO;
import com.xhwl.logistics.bo.cent.DeviceBO;
import com.xhwl.logistics.bo.input.QueryVehiclePassageBO;
import com.xhwl.logistics.dto.query.VehiclePassageDTO;
import com.xhwl.logistics.entity.VehiclePassage;
import com.xhwl.logistics.enums.VehiclePassageTypeEnum;
import com.xhwl.logistics.po.VehiclePassagePO;
import com.xhwl.logistics.po.VehiclePassageSecondPO;
import com.xhwl.logistics.vo.VehiclePassageSecondVO;
import com.xhwl.logistics.vo.VehiclePassageThirdVO;
import com.xhwl.logistics.vo.VehiclePassageVO;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.NullValueMappingStrategy;

import java.util.LinkedList;
import java.util.List;

@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface VehiclePassageConverter {

    //********* Common *********
    default String toPassTypeString(Integer passType) {
        return VehiclePassageTypeEnum.toVehiclePassageTypeEnum(passType).getDescription();
    }
    //********* Common *********


    //********* DTO--->BO *********
    QueryVehiclePassageBO vehiclePassageDTO2QueryVehiclePassageBO(VehiclePassageDTO vehiclePassageDTO);
    //********* DTO--->BO *********


    //********* PO--->BO *********
    VehiclePassageBO toVehiclePassageBO(VehiclePassagePO vehiclePassagePO, String projectName);

    VehiclePassageSecondBO vehiclePassageSecondPO2VehiclePassageSecondBO(VehiclePassageSecondPO vehiclePassageSecondPO);
    //********* PO--->BO *********


    //********* BO--->VO *********
    List<VehiclePassageVO> vehiclePassageBOList2VehiclePassageVOList(List<VehiclePassageBO> vehiclePassageBOList);
    VehiclePassageVO vehiclePassageBO2VehiclePassageVO(VehiclePassageBO vehiclePassageBO);

    List<VehiclePassageSecondVO> vehiclePassageSecondBOList2VehiclePassageSecondVOList(List<VehiclePassageSecondBO> vehiclePassageSecondBOList);
    VehiclePassageSecondVO vehiclePassageSecondBO2VehiclePassageSecondVO(VehiclePassageSecondBO vehiclePassageSecondBO);
    //********* BO--->VO *********

    //******** POJO--->VO ********
    default List<VehiclePassageThirdVO> vehiclePassageList2VehiclePassageThirdVOList(List<VehiclePassage> vehiclePassageList, List<DeviceBO> deviceBOList,Integer projectId){
        LinkedList<VehiclePassageThirdVO> vehiclePassageThirdVOS = new LinkedList<>();
        for (VehiclePassage vehiclePassage : vehiclePassageList) {
            DeviceBO deviceBO = deviceBOList.stream().filter(s -> {
                if (StringUtils.equals(s.getProjectId().toString(), projectId.toString()) &&
                        StringUtils.equals(s.getNumber(), vehiclePassage.getRemark())) {
                    return true;
                } else {
                    return false;
                }
            }).findAny().orElse(null);
            vehiclePassageThirdVOS.add(vehiclePassage2VehiclePassageThirdVO(vehiclePassage,deviceBO.getId()));
        }
        return vehiclePassageThirdVOS;
    }
    VehiclePassageThirdVO vehiclePassage2VehiclePassageThirdVO(VehiclePassage vehiclePassage,Integer deviceId);
    //******** POJO--->VO ********
}
